home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.01 Jan 90 / MacTutor Help Source / Code Resource Version / C Example / utilities.c < prev   
Encoding:
C/C++ Source or Header  |  1989-08-26  |  3.2 KB  |  83 lines  |  [TEXT/KAHL]

  1. /* Routines for the credits box... */
  2.  
  3. #include "demo.h"
  4.  
  5. /***********************************************************************\
  6. |                     void  Bold_Button( dPtr, itemNum )                    |
  7. |-----------------------------------------------------------------------|
  8. | Purpose :: To draw a thick black line around any dialog box item.        |
  9. |-----------------------------------------------------------------------|
  10. | Arguments ::                                                            |
  11. |     dPtr    -> Pointer to an already opened window.                        |
  12. |     itemNum    -> Item within the dialog to highlight.                        |
  13. |-----------------------------------------------------------------------|
  14. | Returns :: void.                                                        |
  15. \***********************************************************************/
  16.  
  17. void Bold_Button( dPtr, itemNum )
  18. DialogPtr    dPtr;
  19. int            itemNum;
  20.  {
  21.      Rect        iBox;            /* The rectangle for the button        */
  22.      int            iType;            /* Type of dialog item                */
  23.      Handle        iHandle;        /* Pointer to the item                */
  24.      PenState    oldPenState;    /* Preserve the old drawing state    */
  25.      
  26.      SystemTask();
  27.      SetPort(dPtr);
  28.      GetPenState(&oldPenState);
  29.      GetDItem(dPtr, itemNum, &iType, &iHandle, &iBox);
  30.      InsetRect(&iBox, -4, -4);
  31.      PenSize(3,3);
  32.      FrameRoundRect(&iBox, 16, 16);
  33.      SetPenState(&oldPenState);
  34.  }
  35.  
  36.  
  37. /***********************************************************************\
  38. |                 void  Center_Window( theWindow, bumpUp )                |
  39. |-----------------------------------------------------------------------|
  40. | Purpose :: To center a currently opened - but still invisible -         |
  41. |             window on the screen.  Once the window is centered, it     |
  42. |             should then be made visible for the user.                    |
  43. |-----------------------------------------------------------------------|
  44. | Arguments ::                                                            |
  45. |     theWindow    -> Pointer to an already opened window.                    |
  46. |     bumpUp        -> A percentage from center to move the window up.        |
  47. |                   Sometimes a perfectly centered window (bumpUp=0) is    |
  48. |                   annoying to a user, so I provide this facility. Note    |
  49. |                   that a negative value will push the window down.        |
  50. |    isModeless    -> If so, add an additional 20 pixels for the drag bar. |
  51. |-----------------------------------------------------------------------|
  52. | Returns :: void.                                                        |
  53. \***********************************************************************/
  54.  
  55. void Center_Window(theWindow,bumpUp,isModeless)
  56. DialogPtr    theWindow;
  57. int            bumpUp;
  58. Boolean        isModeless;
  59.  {
  60.     Rect    tempRect;       /* Temporary rectangle                     */
  61.     int        pixels;            /* Raise from center this amount        */
  62.     int        menuBar = 20;    /* Compensate 20 pixels for menu bar    */
  63.     
  64.     /* Compute centering information */
  65.      tempRect.top = theWindow->portRect.top;
  66.     tempRect.left = theWindow->portRect.left;
  67.     tempRect.bottom = theWindow->portRect.bottom;
  68.     tempRect.right = theWindow->portRect.right;
  69.     tempRect.top = ((screenBits.bounds.bottom + menuBar + (isModeless ? 20 : 0) - 
  70.                      screenBits.bounds.top) - (tempRect.bottom - tempRect.top)) / 2;
  71.     tempRect.left = ((screenBits.bounds.right - screenBits.bounds.left) - 
  72.                     (tempRect.right - tempRect.left)) / 2;
  73.  
  74.     /* Apply any bump-up factor */
  75.     pixels = tempRect.top * (bumpUp / 100.0);
  76.     tempRect.top = tempRect.top - pixels;
  77.  
  78.     /* Now center window & make it visible */
  79.     MoveWindow(theWindow, tempRect.left, tempRect.top, TRUE);
  80.     SetPort(theWindow);              
  81.   }
  82.   
  83.